﻿using System;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Command;
using SessionHunter.DataAccess;

namespace SessionHunter.ViewModel
{
    /// <summary>
    /// Partial class to keep all the relay commands for the main view model
    /// </summary>
    public partial class MainViewModel
    {
        #region RelayCommands - Controls
        /// <summary>
        /// Command for the number of sessions to show
        /// </summary>
        public RelayCommand<string> Command_NumberOfSessions { get; private set; }
        /// <summary>
        /// Command for whether to show all sessions
        /// </summary>
        public RelayCommand<bool> Command_ShowAllSessions { get; private set; }
        /// <summary>
        /// Command for create/expire colum setting change
        /// </summary>
        public RelayCommand<bool> Command_ShowCreateExpires { get; private set; }
        /// <summary>
        /// Command for show lock info setting change
        /// </summary>
        public RelayCommand<bool> Command_ShowLockInfo { get; private set; }
        /// <summary>
        /// Command for application checkbox
        /// </summary>
        public RelayCommand<bool> Command_ShowApplication { get; private set; }
        /// <summary>
        /// Command for order by radio button
        /// </summary>
        public RelayCommand<string> Command_OrderBy { get; private set; }
        #endregion

        #region RelayCommands - Events
        /// <summary>
        /// Command run when you select an item
        /// </summary>
        public RelayCommand<SelectionChangedEventArgs> Command_ListSessionChanged { get; private set; }
        #endregion

        #region RelayCommands - Buttons
        /// <summary>
        /// Command for references button
        /// </summary>
        public RelayCommand Command_References { get; private set; }
        /// <summary>
        /// Command for refresh button
        /// </summary>
        public RelayCommand Command_Refresh { get; private set; }
        /// <summary>
        /// Command for button to change the connection string
        /// </summary>
        public RelayCommand Command_Connection { get; private set; }
        /// <summary>
        /// Command for when the view has finished loading
        /// </summary>
        public RelayCommand Command_ViewLoaded { get; private set; }
        #endregion

        /// <summary>
        /// Configures all of the relay commands for the MainViewModel.
        /// </summary>
        private void ConfigureRelayCommands()
        {
            Command_NumberOfSessions = new RelayCommand<string>(param => _applicationRepository.SaveOption<int>(ApplicationRepository.PersistedSettings.NumberOfSessions, Int32.Parse(param)));
            Command_ShowAllSessions = new RelayCommand<bool>(SetShowAllSessions);
            Command_ShowCreateExpires = new RelayCommand<bool>(param => _applicationRepository.SaveOption<bool>(ApplicationRepository.PersistedSettings.ShowCreateExpires, param));
            Command_ShowLockInfo = new RelayCommand<bool>(param => _applicationRepository.SaveOption<bool>(ApplicationRepository.PersistedSettings.ShowLockInfo, param));
            Command_ShowApplication = new RelayCommand<bool>(param => _applicationRepository.SaveOption<bool>(ApplicationRepository.PersistedSettings.Application, param));
            Command_OrderBy = new RelayCommand<string>(param => SaveOptionByString<ApplicationOptions.OrderByParameter>(ApplicationRepository.PersistedSettings.OrderBy, param));
            Command_References = new RelayCommand(References);
            Command_Refresh = new RelayCommand(Refresh);
            Command_Connection = new RelayCommand(ChangeDatabaseConnection);
            Command_ListSessionChanged = new RelayCommand<SelectionChangedEventArgs>(param => PopulateSessionItemsList(param), parm => (HasSessions));
            Command_ViewLoaded = new RelayCommand(ViewLoaded);
        }
    }
}
